home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 1.9 KB | 78 lines | [TEXT/ttxt] |
- ---<<<
-
- in module WebBrowser
-
- -- Simple code that downloads an ascii file listing the available
- -- title containers. This list is displayed in a window. Clicking on a name
- -- downloads and opens the title container.
-
- function fetchContainer data button -> (
- button.enabled := false
- openContainerFromURL data
- button.enabled := true
- )
-
- function parseIndex stream -> (
- local d := new Array
- repeat until (isPastEnd stream) do (
- append d #((getline stream), (getline stream))
- )
- d
- )
-
- function getIndex url -> (
- local p := geturl WebAccessManager url
- parseIndex p[2]
- )
-
- function showIndex url -> (
- local idx := getIndex url
- local window := new window
- local y := 50
- local x := 5
- local bc := new actuatorcontroller space: window
- bc.wholespace := true
- local th := new textpresenter boundary: (new Rect x2: 300 y2: y)\
- target: url
- th.y := 20
- -- setdefaultattr th @size 16
- -- setdefaultattr th @weight @bold
- prepend window th
- for i in idx do (
- local description := i[1]
- local url := i[2]
- local tp1 := new TextPresenter target: description \
- boundary: (new Rect x2: 200 y2: 20)
- local tp2 := new TextPresenter target: description \
- stroke: blackbrush \
- boundary: (new Rect x2: 200 y2: 20)
-
- local tp3 := new TextPresenter target: "Downloading.." \
- stroke: (new brush color: redcolor) \
- fill: whitebrush \
- boundary: (new Rect x2: 200 y2: 20)
-
- local pb := new PushButton \
- releasedPresenter: tp1 \
- pressedPresenter: tp2 \
- disabledPresenter: tp3
- pb.x := x
- pb.y := y
- prepend window pb
- pb.activateAction := fetchContainer
- pb.authorData := url;
- y := y + 20
- )
- show window
- )
-
- function timedownload url -> (
- local startTime := theeventtimestampclock.time
- local headers := (getURLToTempFile WebAccessManager url)[1]
- local endtime := theeventtimestampclock.time
- local size := headers["content-length" as string]
- (size as float) / ((endtime - starttime) as integer) * starttime.scale
- )
-
- -->>
-